<?php
class Mould extends Object
{
	function children()
	{
		global $db;
		$arr = NULL;
		$sql = "select * from Mould where PID={$this->MID} order by `MID` asc";
		$result = $db->query($sql);
		while($row = $db->fetch_array($result))
		{
			$arr[] = new Mould($row);
		}
		return $arr;
	}
	function parent()
	{
		global $db;
		$mould = NULL;
		if($this->PID == 0)
			return $mould;
		$sql = "select * from Mould where MID={$this->PID}";
		$result = $db->query($sql);
		if($row = $db->fetch_array($result))
		{
			$mould = new Mould($row);
		}
		return $mould;
	}
	function delete()
	{
		global $dbs;
		$sql = "delete * from Mould where MID={$this->MID}";
		$db->query($sql);
		$children = $this->children();
		if($children)
		{
			foreach($children as $child)
				$child->delete();
		}
		return true;
	}
}
/*
CREATE TABLE `Mould` (
  `MID` int(10) unsigned NOT NULL auto_increment,
  `MName` varchar(255) NOT NULL,
  `MUrl` varchar(255) NOT NULL,
  `PID` int(10) unsigned NOT NULL default '0',
  `MInfo` varchar(255) default NULL,
  `UID` int(10) unsigned NOT NULL default '0',
  `AddTime` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`MID`),
  KEY `MName` (`MName`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
*/
?>